//
//  ST_RechargeSweetCoinHeader.swift
//  btvideo
//
//  Created by mac on 2020/7/1.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift

class ST_RechargeSweetCoinHeader: UIView {

    static let height:CGFloat = 80+15+5
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.addSubview(root_view)
        root_view.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.init(top: 15, left: 15, bottom: 5, right: 15))
        }
        
        root_view.addSubview(cover_image_view)
        cover_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(28)
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(20)
        }
        
        root_view.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(cover_image_view.snp.right).offset(10)
        }
        
        root_view.addSubview(number_label)
        number_label.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalToSuperview().offset(-20)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK: - Properties
    fileprivate lazy var root_view:UIView = {
       let control = UIView()
        control.cornerRadius = 10
        control.backgroundColor = .white
        return control
    }()
    fileprivate lazy var cover_image_view:UIImageView = {
        let control = UIImageView.init(image: ST_ImageUtils.imageName("充值_coin_icon"))
          return control
      }()
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.text = "我的甜心币"
        control.textColor = Color.init(hexString: "#333333")
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 16, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var number_label:UILabel = {
        let control = UILabel.init()
        return control
    }()
    
    
    var coin = 0{
        didSet{
            
            let coinNumberStr = NSMutableAttributedString.init(string: self.coin.string)
            
            coinNumberStr.addAttributes([NSAttributedString.Key.foregroundColor:UIColor.init(hex: 0x333333)!,NSAttributedString.Key.font:UIFont.init(name: "DINPro-Black", size: 32)!], range: NSRange.init(location: 0, length: coinNumberStr.length))
            
            let unitStr = NSMutableAttributedString.init(string: " 个")
            
            unitStr.addAttributes([NSAttributedString.Key.foregroundColor:UIColor.init(hex: 0x61666F)!,NSAttributedString.Key.baselineOffset:1,NSAttributedString.Key.font:UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.semibold)], range: NSRange.init(location: 0, length: unitStr.length))
            
            coinNumberStr.append(unitStr)
            
            number_label.attributedText = coinNumberStr
        }
    }
    
}
